package com.coin.controller;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.coin.exchange.ether.api.EtherApi;
import com.coin.exchange.ether.vo.EtherRequestVO;
import com.coin.framework.bean.ResultForm;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/rest/eth")
public class EtherController {

	private static Logger logger = LoggerFactory.getLogger(EtherController.class);
	
	@Autowired
	private EtherApi etherApi;

	@ApiOperation(value = "Get Ether Balance")
	@RequestMapping(value = "/getEtherBalance", method = RequestMethod.POST)
	public Object getEtherBalance(@RequestBody @Valid EtherRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String result = etherApi.getEtherBalance(vo.getAddress(), vo.getApikey());
			resultForm = ResultForm.createSuccessResultForm(result, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}
	
}
